package com.pet.controller;


import com.pet.service.SysUserService;
import com.pet.utils.JwtHelper;
import com.pet.utils.Result;
import com.pet.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@CrossOrigin("*")
@RestController
@Api(tags = "登录管理控制器")
@RequestMapping(value = "/lovePet/system/index")
public class LoginController {
    @Autowired
    SysUserService sysUserService;
    /**
     *  登录接口
     * @return
     */
    @ApiOperation("登录方法")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo)
    {
        return Result.ok("1");
    }

    @ApiOperation("info方法")
    @GetMapping("/info")
    public Result info(HttpServletRequest request)
    {
        //a.获取请求头的 token 字符串
        String token = request.getHeader("token");

        //b.从token 字符串获取用户名称 (id)
        String username = JwtHelper.getUsername(token);

        // c.根据用户名称获取用户信息 （a.基本信息  b.菜单权限信息  和 c.按钮权限信息）
        Map<String,Object> map =  sysUserService.getUserInfo(username);
        return Result.ok(map);
    }
    /**
     * 退出
     * @return
     */
    @ApiOperation("退出")
    @PostMapping("/logout")
    public Result logout(){
        return Result.ok();
    }
}
